package org.liveboardgames.agricola.control.delegates.action.overrideaction
{
	import org.liveboardgames.agricola.control.delegates.action.overrideaction.ActionOverride;
	import org.liveboardgames.agricola.control.delegates.action.overrideaction.ActionOverrideFactory;
	import org.liveboardgames.agricola.vo.action.Action;
	import org.liveboardgames.agricola.vo.common.Target;
	
	public class ActionOverrider
	{
		public function overrideAction(originalAction:Action, target:Target):Action
		{
			var overriddenAction:Action = originalAction.clone();

			// Get the target of the action, i.e. the one that will 
			// benefit from it
			if (target != null)
			{
				overriddenAction.target = target;
			}

			// Now override the action with player-specific data
			var actionOverride:ActionOverride = ActionOverrideFactory.getActionOverride(overriddenAction, target);
			if (actionOverride != null)
			{
				actionOverride.overrideAction();
			}

			return overriddenAction;
		}

	}
}